import { type Directive } from "vue"
import { useUserStore } from "@/store/modules/user"
import { useAuthStore } from "@/store/modules/auth"

// 权限指令
export const auth: Directive = {
  mounted(el, binding) {
    const { value } = binding
    const userStore = useUserStore()
    const authStore = useAuthStore()
    
    if (userStore.roles.includes('admin')) return;

    if (!value.some((key: string) => authStore.auth[key])) {
      el.remove();
    }
  }
}
